// pages/usingSitua/usingSitua.js
const app = getApp()
const lbbService = require('../service/service.js')

Page({

  /**
   * 页面的初始数据
   */
  data: {
    tabNum: 1
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      pileCode: options.pileCode,
      scrollHeight: app.getScrollHeight(60)
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getRfidInfo()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  toggleTab: function (e) {
    let that = this
    console.log(e)
    let tabNum = e.currentTarget.dataset.num
    that.setData({
      tabNum: tabNum
    })
    if (that.data.tabNum == '2' && !that.data.blueErrInfo){
      that.getblueInfo()
    } else if (that.data.tabNum == '1' && !that.data.rfidErrInfo) {
      that.getRfidInfo()
    } else if (that.data.tabNum == '3' && !that.data.ejectErrInfo){
      that.getSwitchInfo()
    } else if (that.data.tabNum == '4' && !that.data.switchErrInfo) {
      that.getBoxHookStatInfo()
    }
  },
  getblueInfo: function(){
    let that = this
    lbbService.getBlueNoConInfo({ pileId: parseInt(that.data.pileCode)},function(res){
      that.setData({
        errList: res.data
      })
    })
  },
  getRfidInfo: function () {
    let that = this
    lbbService.getRFIDNoReadInfo({ pileId: parseInt(that.data.pileCode) }, function (res) {
      that.setData({
        errList: res.data
      })
    })
  },
  getEjectInfo: function () {
    let that = this
    lbbService.getBoxNoEjectInfo({ pileId: parseInt(that.data.pileCode) }, function (res) {
      that.setData({
        errList: res.data
      })
    })
  },
  getSwitchInfo: function () {
    let that = this
    lbbService.getBoxSwitchInfo({ pileId: parseInt(that.data.pileCode) }, function (res) {
      that.setData({
        errList: res.data
      })
    })
  },
  getBoxHookStatInfo: function () {
    let that = this
    lbbService.getBoxHookStatInfo({ pileId: parseInt(that.data.pileCode) }, function (res) {
      that.setData({
        errList: res.data
      })
    })
  },
})